/**
 * 退货单编辑页面
 */

var sysReturnEdit = {};
sysReturnEdit.operation = {};
sysReturnEdit.orderSkuList = null;
$sysReturnSkuTable = null;
addBillItemTable = null;
addNotBillItemTable = null;
addLgstNoTable = null;

var nEditingAddBillItem = null;
var nEditingAddNotBillItem = null;
var nEditingSysReturnSku = null;

window.onload = function() {
    $sysReturnSkuTable.fnDraw();
};

var map = {};//记录原始的规格数据
var mapBill = {};
var mapNotBill = {};
/**
 * 初始化
 */
$(function () {
    map = {};
    mapBill = {};
    mapNotBill = {};
    var sysReturnId = sysReturnEdit.extractId();
    var orderId = sysReturnEdit.extractOrderId();
    sysReturnEdit.sysReturnId = sysReturnId;
    sysReturnEdit.orderId = orderId;

    // 从后台加载退货原因类型列表
    sysReturnEdit.initReturnReasonList();
    // 从后台加载物流公司列表
    sysReturnEdit.initLgstList();
    //加载基本信息以及商品信息
    sysReturnEdit.loadDetail();
    // 从后台加载仓库列表
    sysReturnEdit.initStorList();
    //初始化页面控件最大长度
    sysReturnEdit.initComp();


    // 初始化校验
    $("#sysReturnForm").validate({
        debug: true,
        ignore: "",
        errorPlacement: function (error, element) {
            error.insertAfter(element);
        }
    });

    /**
     * 选择快递单号
     */
    $("#btnLgstNo").click(function(){
        initLgstNoTable();
    });

    $('#addLgstNoTable').on('click', 'a.edit', function (e) {
        // e.preventDefault();
        var nRow = $(this).parents('tr')[0];
        var aData = addLgstNoTable.fnGetData(nRow);
        $("#lgstNo").val(aData[3]);
        $('#modalAddLgstNo').modal('hide');
    });

    // 清空快递单号
    $("#btnLgstNoClear").click(function(){
        $('#lgstNo').val('');
    });

    $("#btnReturnClose").click(function(){
        window.top.window.$('#modalSysReturnDetailClose').click();
    });

//    window.top.window.$("#modalSysReturnDetail").on('hide.bs.modal', function() {
//        // 父窗体归还本页的编辑对话框
//        window.top.window.returnCustomModalDialog();
//    });

    $('#sysReturnSkuTable').on('click', 'a.edit', function (e) {
        //e.preventDefault();alert();
        var nRow = $(this).parents('tr')[0];
        if (nEditingSysReturnSku !== null && nEditingSysReturnSku != nRow) {
            rollbackRowSysReturnSku($sysReturnSkuTable, nEditingSysReturnSku);
            editRowSysReturnSku($sysReturnSkuTable, nRow);
            nEditingSysReturnSku = nRow;
        } else if (nEditingSysReturnSku == nRow && this.innerHTML == "保存") {
            saveRowSysReturnSku($sysReturnSkuTable, nEditingSysReturnSku);
            nEditingSysReturnSku = null;
        } else {
            editRowSysReturnSku($sysReturnSkuTable, nRow);
            nEditingSysReturnSku = nRow;
        }
    });

    $('#sysReturnSkuTable').on('click', 'a.delete', function (e) {
        deleteflg = true;
        // e.preventDefault();
        var nRow = $(this).parents('tr')[0];
        window.top.window.$("#modalConfirmContent").text("要删除该行吗?");
        window.top.window.$('#btnModalOK').unbind();
        window.top.window.$("#btnModalOK").on('click', '',{nRow:nRow,orderSkuId:$(this).attr("orderSkuId")}, delSku);
        window.top.window.$('#modal-confirm').modal({show:true, backdrop:'static'});
    });

    function delSku(event){
        if (nEditingSysReturnSku !== null && nEditingSysReturnSku != event.data.nRow) {
            saveRowSysReturnSku($sysReturnSkuTable, nEditingSysReturnSku);
        }
        //删除数据库存在的数据的时候，需要记录
        $sysReturnSkuTable.fnDeleteRow(event.data.nRow);
        nEditingSysReturnSku = null;
    }

    $('#addBillItemTable').on('click', 'a.edit', function (e) {
        // e.preventDefault();
        var nRow = $(this).parents('tr')[0];
        if (nEditingAddBillItem !== null && nEditingAddBillItem != nRow) {
            rollbackRowAddBillItem(addBillItemTable, nEditingAddBillItem);
            editRowAddBillItem(addBillItemTable, nRow);
            nEditingAddBillItem = nRow;
        } else if (nEditingAddBillItem == nRow && this.innerHTML == "保存") {
            saveRowAddBillItem(addBillItemTable, nEditingAddBillItem);
            nEditingAddBillItem = null;
        } else {
            editRowAddBillItem(addBillItemTable, nRow);
            nEditingAddBillItem = nRow;
        }
    });



//单据商品选择 确定事件----------------------------------------------------------------
    $("#btnBillItem").click(function(){
        var isEmpty = '1';
        var n = addBillItemTable.fnGetData.length;
        //
        $('input:checkbox[name=chkOrderSku]:checked').each(function(i) {
            isEmpty = '0';
            var nRow = $(this).parents('tr')[0];
            var aData = addBillItemTable.fnGetData(nRow);
            n=n+1;

            //获取单据主键
            var keyorderSkuId = $(this).parent().parent().find(".edit").attr("orderSkuId");
            var billKey = aData[1]+":"+aData[2]+":"+aData[5]+":"+keyorderSkuId;

            $sysReturnSkuTable.fnAddData([
                aData[1],
                aData[2],
                aData[3],
                aData[4],
                aData[5],
                aData[6],
                aData[9],
                aData[10],
                aData[11],
                aData[12],
                '<a href="javascript:;" class="edit" orderSkuId="'+mapBill[billKey].orderSkuId+'" rowIndex ="'+n+'">编辑</a>&nbsp;<a href="javascript:;" class="delete" orderSkuId="" rowIndex ="'+n+'">删除</a>'
            ]);
            $sysReturnSkuTable.fnDraw();

            //
            var obj = new Object();
            obj.skuId = mapBill[billKey].skuId;
            obj.skuCode = mapBill[billKey].skuCode;
            obj.skuName = mapBill[billKey].skuName;
            obj.goodsId = mapBill[billKey].goodsId;
            obj.goodsCode = mapBill[billKey].goodsCode;
            obj.goodsName = mapBill[billKey].goodsName;
            obj.qty = mapBill[billKey].qty1;
            obj.remark = mapBill[billKey].remark;
            obj.isGift = mapBill[billKey].isGift;
            obj.isOrderSku = "订单"==aData[1]?"y":"r";
            obj.factUnitPrice = mapBill[billKey].factUnitPrice;
            obj.divideGoodsFee = mapBill[billKey].divideGoodsFee;
            obj.sourceSkuId = mapBill[billKey].sourceSkuId;
            obj.ecOid = mapBill[billKey].ecOid;
            obj.oid = mapBill[billKey].oid;
            obj.sourceCode = mapBill[billKey].sourceCode;

            obj.orderSkuId = mapBill[billKey].orderSkuId;
            obj.returnSkuId = null;

            if (!map[aData[1]+":"+aData[2]+":"+aData[5]+":"+obj.orderSkuId]){
                map[aData[1]+":"+aData[2]+":"+aData[5]+":"+obj.orderSkuId] = obj;
            }

        });

        if (isEmpty == '1'){
            window.top.window.showModalAlertPretty("请选择要处理的数据");
        } else {
            $("#btnBillItemClose").click();
        }

    });

    //非单据商品选择
    $("#btnNotBillItem").click(function(){

        var isEmpty = '1';
        var n = addNotBillItemTable.fnGetData.length;
        //
        $('input:checkbox[name=chkPrjSku]:checked').each(function(i) {
            isEmpty = '0';
            var nRow = $(this).parents('tr')[0];
            var aData = addNotBillItemTable.fnGetData(nRow);
            n=n+1;
            $sysReturnSkuTable.fnAddData([
                '非单据',
                '否',
                aData[1],
                aData[2],
                aData[3],
                aData[4],
                aData[5],
                '0',
                '0',
                '',
                '<a href="javascript:;" class="edit" orderSkuId="" rowIndex ="'+n+'">编辑</a>&nbsp;<a href="javascript:;" class="delete" orderSkuId="" rowIndex ="'+n+'">删除</a>'
            ]);
            $sysReturnSkuTable.fnDraw();
            var obj = new Object();
            obj.skuId = mapNotBill["非单据:否:"+aData[3]].skuId;
            obj.skuCode = mapNotBill["非单据:否:"+aData[3]].skuCode;
            obj.skuName = mapNotBill["非单据:否:"+aData[3]].skuName;
            obj.goodsId = mapNotBill["非单据:否:"+aData[3]].goodsId;
            obj.goodsCode = mapNotBill["非单据:否:"+aData[3]].goodsCode;
            obj.goodsName = mapNotBill["非单据:否:"+aData[3]].goodsName;
            obj.qty = mapNotBill["非单据:否:"+aData[3]].qty;
            obj.remark = "";
            obj.isGift = "否";
            obj.isOrderSku = "n";
            obj.factUnitPrice = mapNotBill["非单据:否:"+aData[3]].factUnitPrice;
            obj.divideGoodsFee = "0";
            obj.sourceSkuId = "";
            obj.ecOid = "";
            obj.sourceCode = "";

            obj.returnSkuId = null;

            if (!map["非单据:否:"+aData[3]+":"]){
                map["非单据:否:"+aData[3]+":"] = obj;
            }

            // map["非单据:否:"+aData[3]+":"] = obj;
        });

        if (isEmpty == '1'){
            window.top.window.showModalAlertPretty("请选择要处理的数据");
        } else {
            $("#btnNotBillItemClose").click();
        }

    });



//保存----------------------------------------------------------------------------
    $("#btnSaveSysReturn").click(function(){
        var flg = true;
        if (!$sysReturnSkuTable.fnGetData.length){
            window.top.window.showScoMessage('error', "至少包含1条明细商品");
            flg = false;
        }

        var varStorType = $("#storId option:selected").eq(0).attr("cainiaoType");
        if(varStorType == "gn" && $('#wmsStockinCode').val().replace(/(^\s*)|(\s*$)/g, "") == ""){
            window.top.window.showScoMessage('error', "仓库类型为菜鸟国内仓时，仓库入库单号不能为空");
            flg = false;
        }

        if (flg){
            var returnInfo = new Object();
            var sysReturnVO = new Object();
            if (!!sysReturnEdit.sysReturnId) {
                //修改
            }else{
                //新增
                sysReturnVO.shopName = $("#shopName").val();
                // sysReturnVO.shopId = $("#shopId").val();
                sysReturnVO.tradeCode = $("#tradeCode").val();
                sysReturnVO.orderCode = $("#orderCode").val();
                sysReturnVO.sourceId = $("#orderId").val();
                sysReturnVO.sourceCode = $("#orderCode").val();
                sysReturnVO.buyerNick = $("#buyerNick").val();
                sysReturnVO.provName =$("#provName").val();
                sysReturnVO.cityName =$("#cityName").val();
                sysReturnVO.distName =$("#distName").val();
            }

            sysReturnVO.shopId = $("#shopId").val();

            sysReturnVO.returnId = $("#returnId").val();
            sysReturnVO.refundReasonId = $("#refundReasonId").val();
            sysReturnVO.refundReasonName = $("#refundReasonId option:selected").eq(0).text();
            sysReturnVO.returnReasonId = $("#refundReasonId").val();
            sysReturnVO.returnReasonName = $("#refundReasonId option:selected").eq(0).text();
            sysReturnVO.remark = $("#remark").val();

            sysReturnVO.cons = $("#cons").val();
            sysReturnVO.consTel = $("#consTel").val();
            sysReturnVO.consMobile = $("#consMobile").val();
            sysReturnVO.consAddr = $("#consAddr").val();

            sysReturnVO.lgstId = $("#lgstId").val();
            sysReturnVO.lgstCode = $("#lgstId option:selected").eq(0).attr("lgstCode");
            sysReturnVO.lgstName = $("#lgstId option:selected").eq(0).text();

            sysReturnVO.lgstNo = $("#lgstNo").val();

            sysReturnVO.storId = $("#storId").val();
            sysReturnVO.storCode = $("#storId option:selected").eq(0).attr("storCode");
            sysReturnVO.storName = $("#storId option:selected").eq(0).text();

            sysReturnVO.wmsStockinCode = $("#wmsStockinCode").val();

            if (!!sysReturnEdit.sysReturnId) {
                returnInfo.action = "update";
            } else {
                returnInfo.action = "insert";
            }
            returnInfo.sysReturnVO = sysReturnVO;

            //sku信息
            var sysReturnSkuList = new Array();
            var sysReturnSkuListdelete = new Array();
            var mapTemp = {};
            $('#sysReturnSkuTable tbody tr').each(function(){
                var sysReturnSkuVO = new Object();
                var aData = $sysReturnSkuTable.fnGetData(this);
                if (aData == null){
                    return;
                }

                var keyorderSkuId = $(this).find(".edit").attr("orderSkuId");
                var returnSkuKey = aData[0]+":"+aData[1]+":"+aData[4]+":"+keyorderSkuId;

                if (map[returnSkuKey].returnSkuId==null){
                    map[returnSkuKey].action = "insert";
                } else {
                    map[returnSkuKey].action = "update";
                }
                map[returnSkuKey].deleted = "n";
                map[returnSkuKey].qty = aData[6];
                map[returnSkuKey].remark = aData[9];
                map[returnSkuKey].factUnitPrice = aData[7];
                sysReturnSkuList.push(map[returnSkuKey]);
                var obj = new Object();
                obj = map[returnSkuKey];
                mapTemp[returnSkuKey] = obj;
                delete map[returnSkuKey];
            });

            $.each(map,function(key,values){
                // map[aData[0]+":"+aData[1]+":"+aData[4]].action = "delete";
                map[key].deleted = "y";
                map[key].action = "update";
                // sysReturnSkuList.push(map[aData[0]+":"+aData[1]+":"+aData[4]]);
                sysReturnSkuListdelete.push(map[key]);
            });

            returnInfo.sysReturnSkuList = sysReturnSkuList.concat(sysReturnSkuListdelete);

            var loading = window.top.window.getIndexBusyOverlay();
            
            $.ajax({
                type: "POST",
                url: "/sysReturnManager/saveSysReturn.action",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(returnInfo),
                dataType: "json",
//                async: false,
                beforeSend:function(){
                    if(loading) {
                    	loading.settext("正在处理中，请稍后...");
                    }
                },
                success: function (data) {
                	loading.remove();
                    if (data.result == "success") {
                        window.top.window.showScoMessage('ok', data.msg);
                        $('#modalSysReturnDetail', window.top.document).find("#modalSysReturnDetailClose").click();
                    } else if (data.result == "skuError") {
                        $.each(mapTemp,function(key,values){
                            map[key] = values;
                        });
                        var reg = new RegExp(/\\n/,"g");
                        window.top.window.showModalAlertPretty(data.msg.replace(reg, "<br/>"));
                    } else {
                        $.each(mapTemp,function(key,values){
                            map[key] = values;
                        });
                        window.top.window.showScoMessage('error', data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus) {
                	loading.remove();
                    if (XMLHttpRequest.status == 500) {
                        var result = eval("(" + XMLHttpRequest.responseText + ")");
                        window.top.window.showScoMessage('error', result.errorObject.errorText);
                    }
                }
            });
        }
    });

    $('#addNotBillItemTable').on('click', 'a.edit', function (e) {
        // e.preventDefault();
        var nRow = $(this).parents('tr')[0];
        if (nEditingAddNotBillItem !== null && nEditingAddNotBillItem != nRow) {
            rollbackRowAddNotBillItem(addNotBillItemTable, nEditingAddNotBillItem);
            editRowAddNotBillItem(addNotBillItemTable, nRow);
            nEditingAddNotBillItem = nRow;
        } else if (nEditingAddNotBillItem == nRow && this.innerHTML == "保存") {
            saveRowAddNotBillItem(addNotBillItemTable, nEditingAddNotBillItem);
            nEditingAddNotBillItem = null;
        } else {
            editRowAddNotBillItem(addNotBillItemTable, nRow);
            nEditingAddNotBillItem = nRow;
        }
    });

    // 绑定查询按钮click
    $("#btnPrjSkuSearch").click(function() {
        doQuery();
    });

    // 全选，全不选
    $("#chkAllNotBill").click(function() {
        var checkboxes = document.getElementsByName('chkPrjSku');
        for (var i = 0; i < checkboxes.length; i++) {
            var checkbox = checkboxes[i];
            if (!$(this).get(0).checked) {
                checkbox.checked = false;
            } else {
                checkbox.checked = true;
            }
        }
    });

    // 全选，全不选
    $("#chkAllBill").click(function() {
        var checkboxes = document.getElementsByName('chkOrderSku');
        for (var i = 0; i < checkboxes.length; i++) {
            var checkbox = checkboxes[i];
            if (!$(this).get(0).checked) {
                checkbox.checked = false;
            } else {
                checkbox.checked = true;
            }
        }
    });
});

/**
 * 加载页面基础和商品明细信息
 */
sysReturnEdit.loadDetail = function () {
    //初始化 商品明细Table
    sysReturnEdit.initDetailTable();

    if (!!sysReturnEdit.sysReturnId) {
        //退货单修改 加载退货单基本信息
        sysReturnEdit.operation.getReturnBaseDetail(sysReturnEdit.sysReturnId);
    } else if (!!sysReturnEdit.orderId) {
        //退货单新增 加载订单基本信息
        sysReturnEdit.operation.getOrderBaseDetail(sysReturnEdit.orderId);
    }
    setInputSelectTitle();
};


//设置输入框和下拉框不可用的title属性
function setInputSelectTitle(){
		var length = $("input").length;
		for(var i=0;i<length;i++){
			if($("input")[i].disabled || $("input")[i].readOnly){
				$("input")[i].title = $("input")[i].value;
			}
		}
		var sLength = $("select").length;
		for(var i=0;i<sLength;i++){
			if($("select")[i].disabled){
				var childLength = $("select")[i].children.length;
				for(var j=0;j<childLength;j++){
					if($("select")[i].children[j].value == $("select")[i].value){
						$("select")[i].title = $("select")[i].children[j].text;
						break;
					}
				}
				
			}
		}
}

// 初始化页面控件最大长度
sysReturnEdit.initComp = function () {

    $("input[maxlength],textarea[maxlength]", $("#sysReturnForm")).maxlength({
        alwaysShow: false,
        threshold: 40,
        warningClass: "label label-warning",
        limitReachedClass: "label label-danger",
        separator: ' / '
    });
};


// 初始化系统原因类型列表
sysReturnEdit.initReturnReasonList = function () {
    $.ajax({
        type: "GET",
        url: "/returnReasonType/getReturnReasonTypeList.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "start": 0,
            "length": 100,
            "quickSearch": ""
        },
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                initReturnReasonSelector(data.data);
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}

// 初始化原因类型
var initReturnReasonSelector = function (returnReasonList) {
    if (returnReasonList.length > 0) {
        $("#refundReasonId").empty();
        $("#refundReasonId").append("<option value=''>请选择</option>");
        for (var index in returnReasonList) {
            $("#refundReasonId").append("<option value='" + returnReasonList[index].returnReasonId + "'>" + returnReasonList[index].returnReasonName + "</option>")
        }
    }
}

/**
 * 初始化入库仓库列表
 *
 * @returns
 */
sysReturnEdit.initStorList = function () {
    // 初始化仓库列表
    $.ajax({
        type: "GET",
        url: "/stor/getStorageByShopIdNoDelete.action?shopId=" + $("#shopId").val(),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,// 同步
        success: function (data) {
            if (data.result == "success") {
                $("#storId option").remove();
                $("#storId").append("<option value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#storId').append(
                        "<option value='" + value.storId + "' storCode='" + value.storCode + "' cainiaoType='" + value.cainiaoType + "'>" + value.storName + "</option>");
                });
                // debugger;
                $("#storId").val($("#storIdHidden").val());

                storChange();

            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

// 入库仓库变化时
function storChange() {
    var varStorType = $("#storId option:selected").eq(0).attr("cainiaoType");
    //debugger;
    if (varStorType == "gn") {
        $('#wmsStockinCode').removeAttr('readonly');
    } else {
        $('#wmsStockinCode').attr("readonly","readonly");
    }
}

// 入库仓库变化时
$('#storId').on('change', function() {
    $('#wmsStockinCode').val("");

    var varStorType = $("#storId option:selected").eq(0).attr("cainiaoType");
    //debugger;
    if (varStorType == "gn") {
        $('#wmsStockinCode').removeAttr('readonly');
    } else {
        $('#wmsStockinCode').attr("readonly","readonly");
    }
});


/**
 * 初始化物流公司列表
 *
 * @returns
 */
sysReturnEdit.initLgstList = function () {
    // 初始化物流列表
    $.ajax({
        type: "GET",
        url: "/lgst/getLgstByProjectId.action?projectId=" + window.top.window.$("#projectSwitch").val(),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,// 同步
        success: function (data) {
            if (data.result == "success") {
                $("#lgstId option").remove();
                $("#lgstId").append("<option value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#lgstId').append("<option value='" + value.lgstId + "' lgstCode='" + value.lgstCode + "'>" + value.lgstName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 根据订单ID获取订单基本信息以及商品明细
 * @param orderId
 */
sysReturnEdit.operation.getOrderBaseDetail = function (orderId) {
    $.ajax({
        type: "GET",
        url: "/order/getOrderInfo.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "orderId": orderId
        },
        dataType: "json",
        async: false,
        success: function (data) {

            if (data.result == "success") {
                // sysReturnEdit.initCompValue4Edit(data.data);//initAddPage 原来
                sysReturnEdit.initEditPage(data.data,"add");

            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}

/**
 * 根据退货单ID获取退货单明细
 * @param sysReturnId
 */
sysReturnEdit.operation.getReturnBaseDetail = function (sysReturnId) {
    $.ajax({
        type: "GET",
        url: "/sysReturnManager/sysReturnDetail.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "sysReturnId": sysReturnId
        },
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                sysReturnEdit.orderId = data.data.sourceId;
                sysReturnEdit.initEditPage(data.data);
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
};


/**
 * 初始化 页面控件赋值并加载商品明细
 * @param data
 */
sysReturnEdit.initEditPage = function (data,operation) {
    // 根据退货单信息初始化退货单控件取值
    sysReturnEdit.initCompValue4Edit(data,operation);

    // 加载商品明细
    if (!!sysReturnEdit.sysReturnId) {
        //修改退货单 加载退货单商品明细
        sysReturnEdit.loadReturnDetailData(data.returnId);
    } else if (!!sysReturnEdit.orderId) {
        //新增退货单，加载订单和补发单商品明细
//        sysReturnEdit.initOrderSkuSelectList(data.orderId);
        //初始化，添加订单商品的弹窗中的列表数据
//        initBillItemTable();
    }
};

/**
 * 根据退货单信息初始化退货单控件取值
 * @param returnData
 */
sysReturnEdit.initCompValue4Edit = function (returnData,operation) {
    for (var key in returnData) {
        $("input#" + key).val(returnData[key]);
        $("input#" + key + "Hidden").val(returnData[key]);
        $("select#" + key).find("option[value='" + returnData[key] + "']").attr("selected", true);
    }
    $("#shopId").val(returnData["shopId"]);
    
    // 如果是新增，则入库仓库需要设置为默认退货仓库
    if(!!operation&&operation=="add"){
        // 获取默认退货仓库
        sysReturnEdit.updateSelectedStorToDefaultReturn($("#storIdHidden").val());
    }

};

    sysReturnEdit.updateSelectedStorToDefaultReturn = function(storId){
        var shopId = $("#shopId").val();
        var prjId = window.top.window.$("#projectSwitch").val();
        $.ajax({
            type: "GET",
            url: "/shop/getDefaultWarehouseByShopStor.action",
            contentType: "application/json;charset=utf-8",
            data: {
                "shopId": shopId,
                "storId": storId,
                "prjId": prjId
            },
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.result == "success") {
                    returnStorId = data.data;
                    //debugger;
                    if(!!returnStorId){
                        $("#storId").val(returnStorId)
                        $("#storIdHidden").val(returnStorId)
                    }
                } else {
                    window.top.window.showModalAlert(data.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.status == 500) {
                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                    window.top.window.showScoMessage('error', result.errorObject.errorText);
                }
            }
        });

    }


/**
 * 根据退货单ID加载退货明细列表
 * @param returnId
 */
sysReturnEdit.loadReturnDetailData = function (returnId) {
    $.ajax({
        type: "GET",
        url: "/sysReturnManager/getReturnSkuByReturnId.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "returnId": returnId
        },
        dataType: "json",
        "ordering": false,
        async: false,
        success: function (data) {
            if (data.result == "success") {
                // var returnSkuInfo = new Object();
//                $sysReturnSkuTable.rows.add(data.data).draw();
                $.each(data.data, function (n, value) {
                    var returnSkuInfo = new Object();
                    $sysReturnSkuTable.fnAddData([
                        value.skuSource,
                        value.isGift == "n"?"否":"是",
                        value.goodsCode,
                        value.goodsName,
                        value.skuCode,
                        value.skuName,
                        value.returnQty,
                        value.factUnitPrice,
                        value.factMoney,
                        value.remark,
                        '<a href="javascript:;" class="edit" orderSkuId="'+value.orderSkuId+'" rowIndex ="'+n+'">编辑</a>&nbsp;<a href="javascript:;" class="delete" orderSkuId="'+value.orderSkuId+'" rowIndex ="'+n+'">删除</a>'
                    ])
                    $sysReturnSkuTable.fnDraw();

                    //记录原始数据
                    returnSkuInfo.returnSkuId = value.returnSkuId;
                    returnSkuInfo.returnId = value.returnId;
                    returnSkuInfo.skuId = value.skuId;
                    returnSkuInfo.skuCode = value.skuCode;
                    returnSkuInfo.skuName = value.skuName;
                    returnSkuInfo.goodsId = value.goodsId;
                    returnSkuInfo.goodsCode = value.goodsCode;
                    returnSkuInfo.goodsName = value.goodsName;
                    returnSkuInfo.qty = value.qty;
                    returnSkuInfo.remark = value.remark;
                    returnSkuInfo.isGift = value.isGift;
                    returnSkuInfo.isOrderSku = value.isOrderSku;
                    returnSkuInfo.factUnitPrice = value.factUnitPrice;
                    returnSkuInfo.divideGoodsFee = value.divideGoodsFee;
                    returnSkuInfo.sourceSkuId = value.sourceSkuId;
                    returnSkuInfo.ecOid = value.ecOid;
                    returnSkuInfo.oid = value.oid;
                    returnSkuInfo.sourceCode = value.sourceCode;

                    returnSkuInfo.orderSkuId = value.orderSkuId;

                    var vIsGift = value.isGift == "y"?"是":"否";
                    // map[value.isOrderSku+":"+value.isGift+":"+value.skuCode] = returnSkuInfo;
                    map[value.skuSource+":"+vIsGift+":"+value.skuCode+":"+value.orderSkuId] = returnSkuInfo;
                });


            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}


/**
 * 初始化商品信息列表列
 * @param returnId
 */
sysReturnEdit.initDetailTable = function (returnId) {
    $('#sysReturnSkuTable').dataTable().fnClearTable();
    $sysReturnSkuTable = $('#sysReturnSkuTable').dataTable({
        "bPaginate": false,
        // "bAutoWidth": true,
        // "bScrollAutoCss":false,
        // "sScrollY" : '200px',
        // "bSort" : false,
        "searching": false,
        "bDeferRender": true,
        "bDestroy": true,
        "ordering": false,
        "dom": '<"bottom"rtflp>',
        "columnDefs" : [{
        	"className" : "truncate-text",
            "targets" : [ 0 ]
        },{
        	"className" : "truncate-text",
            "targets" : [ 1 ]
        },{
        	"className" : "truncate-text",
            "targets" : [ 2 ]
        },{
        	"className" : "truncate-text",
            "targets" : [ 3 ]
        },{
        	"className" : "truncate-text",
            "targets" : [ 4 ]
        },{
        	"className" : "truncate-text",
            "targets" : [ 5 ]
        },{
        	"className" : "truncate-text",
            "targets" : [ 6 ]
        },{
        	"className" : "truncate-text",
            "targets" : [ 7 ]
        }],
        "createdRow": function ( row, data, index ) {
            //控件有bug：row里的数据和显示出来的数据不一致，没有找到根源，暂时解决一下
            setTimeout(function(){
                for(var i=0; i<data.length; i++) {
                    var tmpText = $('td', row).eq(i).text();
                    $('td', row).eq(i).attr("title", tmpText);
                }
            }, 200);
        },
        "fnDrawCallback": function (oSettings) {
            $("#thOrdering").removeClass("sorting_asc");
        }
    });
}

/**
 * 添加非单据商品点击事件
 */
function addItem(){
    nEditingAddNotBillItem = null;
    $("#chkAllNotBill").removeAttr("checked");
    $('#skuGoodsCode').val("");
    $('#skuGoodsName').val("");
    $('#skuSkuCode').val("");
    $('#skuSkuName').val("");

    $('#modalAddNotBillItem').modal();
    $('#addNotBillItemTable').dataTable().fnClearTable();
    addNotBillItemTable = $('#addNotBillItemTable').dataTable({
        "bPaginate": false,
        "bAutoWidth": true,
//        "bScrollAutoCss":false,
//        "sScrollY" : '200px',
        "bSort" : false,
        "searching": false,
        "bDeferRender": true,
        "bDestroy": true,
        "dom": '<"bottom"rtflp>',
        "fnDrawCallback": function (oSettings) {
            $("#thAllNotBill").removeClass("sorting_asc");
        }
    });

}

/**
 * 添加单据商品点击事件
 */
function addBillItem(){
    $("#chkAllBill").removeAttr("checked");
    $('#modalAddBillItem').modal();
    initBillItemTable();
}

/**
 * 初始化单据商品界面---------------------------------------------------------------------------
 */
function initBillItemTable(){
    $('#addBillItemTable').dataTable().fnClearTable();
    addBillItemTable = $('#addBillItemTable').dataTable({
        "bPaginate": false,
        "bAutoWidth": true,
//        "bScrollAutoCss":false,
//        "sScrollY" : '200px',
        "bSort" : false,
        "searching": false,
        "bDeferRender": true,
        "bDestroy": true,
        "ordering": false,
        "dom": '<"bottom"rtflp>',
        "fnDrawCallback": function (oSettings) {
            $("#thAllBill").removeClass("sorting_asc");
        }
    });



//传递已经添加的单据商品信息，用于排除再次选择情况 begin----------------------------------------------------
    var currentGoodsSku = {};
    $('#sysReturnSkuTable tbody tr').each(function(){
        var sysReturnSkuVO = new Object();
        var aData = $sysReturnSkuTable.fnGetData(this);
        if (!!aData) {
            // map[aData[0] + ":" + aData[1] + ":" + aData[4]].deleted = "n";
            var obj = new Object();

            var keyorderSkuId = $(this).find(".edit").attr("orderSkuId");
            obj = map[aData[0] + ":" + aData[1] + ":" + aData[4]+":"+keyorderSkuId];

            currentGoodsSku[aData[0] + ":" + aData[1] + ":" + aData[4]+":"+ keyorderSkuId] = obj;
        }
    });
//传递已经添加的单据商品信息，用于排除再次选择情况 end------------------------------------------------------


    $.ajax({
        type: "GET",
        url: "/sysReturnManager/getOrderSkuById.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "orderId": sysReturnEdit.orderId
        },
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                $.each(data.data, function (n, value) {
                    var ob = new Object();
                    //var checkbox = '<input name="chkOrderSku" orderSkuId="'+value.orderSkuId+'" type=\"checkbox\" />';
                    var checkbox = value.shipedQty=='0'?'':'<input name="chkOrderSku" orderSkuId="'+value.orderSkuId+'" type=\"checkbox\" />';
                    var operation = value.shipedQty=='0'?'':'<a href="javascript:;" class="edit" orderSkuId="'+value.orderSkuId+'" rowIndex ="'+n+'">编辑</a>';
                    //判断商品是否已经添加过了
                    if (currentGoodsSku[value.skuSource+":"+value.isGift+":"+value.skuCode+":"+value.orderSkuId]){
                        addBillItemTable.fnAddData([
                            '',
                            value.skuSource,
                            value.isGift,
                            value.goodsCode,
                            value.goodsName,
                            value.skuCode,
                            value.skuName,
                            value.qty,
                            value.shipedQty,
                            value.returnQty,
                            value.factUnitPrice,
                            '0',
                            '',
                            value.sn,
                            ''
                        ]);
                    }else {
                        addBillItemTable.fnAddData([
                            checkbox,
                            value.skuSource,
                            value.isGift,
                            value.goodsCode,
                            value.goodsName,
                            value.skuCode,
                            value.skuName,
                            value.qty,
                            value.shipedQty,
                            value.returnQty,
                            value.factUnitPrice,
                            '0',
                            '',
                            value.sn,
                            operation
                        ]);
                    }

                    ob.orderSkuId = value.orderSkuId;
                    ob.orderId = value.orderId;
                    ob.qty = value.qty;
                    ob.skuSource = value.skuSource;
                    ob.goodsId = value.goodsId;
                    ob.goodsCode = value.goodsCode;
                    ob.goodsName = value.goodsName;
                    ob.skuId = value.skuId;
                    ob.skuCode = value.skuCode;
                    ob.skuName = value.skuName;
                    ob.isGift = value.isGift;
                    ob.factUnitPrice = value.factUnitPrice;
                    ob.divideGoodsFee = value.divideGoodsFee;
                    ob.sourceSkuId = value.orderSkuId;
                    ob.ecOid = value.oid;
                    ob.oid = value.oid;
                    ob.sourceCode = value.orderCode;

                    mapBill[value.skuSource+":"+value.isGift+":"+value.skuCode+":"+value.orderSkuId] = ob;
                    // mapBill[value.skuSource+":"+value.isGift+":"+value.skuCode] = ob;
                });
            } else {
                // window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}

function rollbackRowSysReturnSku(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    for (var i = 0, iLen = rTds.length; i < iLen; i++) {
        oTable.fnUpdate(aData[i], nRow, i, false);
    }
    oTable.fnDraw();
}

function editRowSysReturnSku(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    rTds[6].innerHTML = '<input type="text"  style="text-align: right;" class="form-control input-small special-num" value="' + aData[6] + '">';
    rTds[7].innerHTML = '<input type="text"  style="text-align: right;" class="form-control input-small special-price" value="' + aData[7] + '">';
    rTds[9].innerHTML = '<input type="text"  style="text-align: right;" class="form-control input-small" value="' + aData[9] + '">';
    rTds[10].innerHTML = aData[10].replace("编辑","保存");

    $(".special-num",rTds).inputmask("9{1,8}", {
        greedy : false,
        placeholder : ''
    });

    $(".special-price",rTds).inputmask("9{1,8}[.99]", {
        greedy : false,
        placeholder : ''
    });


}

function saveRowSysReturnSku(oTable, nRow) {
    var rInputs = $('input', nRow);
    var aData = oTable.fnGetData(nRow);
    var dataAction = aData[10];
    var value = rInputs[0].value;

    //获取orderSkuId主键值
    var keyorderSkuId = $("#sysReturnSkuTable>tbody").find("tr:eq("+nRow._DT_RowIndex+")").find(".edit").attr("orderSkuId");
    var billKey = aData[0]+":"+aData[1]+":"+aData[4]+":"+keyorderSkuId;

    oTable.fnUpdate(rInputs[0].value, nRow, 6, false);
    oTable.fnUpdate(rInputs[1].value, nRow, 7, false);
    oTable.fnUpdate(rInputs[0].value*rInputs[1].value, nRow, 8, false);
    oTable.fnUpdate(rInputs[2].value, nRow, 9, false);
    oTable.fnUpdate(dataAction.replace("保存","编辑"), nRow, 10, false);
    map[billKey].qty = aData[6];
    map[billKey].factUnitPrice = aData[7];
    map[billKey].remark = aData[9];

    // map[aData[0]+":"+aData[1]+":"+aData[4]].returnSkuId = null;
}

function rollbackRowAddBillItem(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    for (var i = 0, iLen = rTds.length; i < iLen; i++) {
        oTable.fnUpdate(aData[i], nRow, i, false);
    }
    oTable.fnDraw();
}

function editRowAddBillItem(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    rTds[9].innerHTML = '<input type="text"  style="text-align: right;" class="form-control input-small special-num" value="' + aData[9] + '">';
    rTds[10].innerHTML = '<input type="text"  style="text-align: right;" class="form-control input-small special-price" value="' + aData[10] + '">';
    rTds[12].innerHTML = '<input type="text"  style="text-align: right;" class="form-control input-small" value="' + aData[12] + '">';
    rTds[13].innerHTML = aData[13].replace("编辑","保存");

    $(".special-num",rTds).inputmask("9{1,8}", {
        greedy : false,
        placeholder : ''
    });

    $(".special-price",rTds).inputmask("9{1,8}[.99]", {
        greedy : false,
        placeholder : ''
    });
}

function saveRowAddBillItem(oTable, nRow) {
    var rInputs = $('input', nRow);
    var aData = oTable.fnGetData(nRow);
    var dataAction = aData[13];
    var value = rInputs[0].value;
    //获取orderSkuId主键值
    var keyorderSkuId = $("#addBillItemTable>tbody").find("tr:eq("+nRow._DT_RowIndex+")").find(".edit").attr("orderSkuId");
    var billKey = aData[1]+":"+aData[2]+":"+aData[5]+":"+keyorderSkuId;

    if(nRow.children[0].children["chkOrderSku"].checked){
    	var inputChecked = "<input name='chkOrderSku' orderSkuId='"+ keyorderSkuId +"' type='checkbox' checked/>";
    	oTable.fnUpdate(inputChecked, nRow, 0, false);
    }
    oTable.fnUpdate(rInputs[1].value, nRow, 9, false);
    oTable.fnUpdate(rInputs[2].value, nRow, 10, false);
    oTable.fnUpdate(rInputs[2].value*rInputs[1].value, nRow, 11, false);
    oTable.fnUpdate(rInputs[3].value, nRow, 12, false);
    oTable.fnUpdate(dataAction.replace("保存","编辑"), nRow, 13, false);
    mapBill[billKey].factUnitPrice = rInputs[2];
    mapBill[billKey].qty1 = rInputs[2];//退入数
    mapBill[billKey].remark = rInputs[3];
}

function rollbackRowAddNotBillItem(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    for (var i = 0, iLen = rTds.length; i < iLen; i++) {
        oTable.fnUpdate(aData[i], nRow, i, false);
    }
    oTable.fnDraw();
}

function editRowAddNotBillItem(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    rTds[5].innerHTML = '<input type="text"  style="text-align: right;" class="form-control input-small special-num" value="' + aData[5] + '">';
    rTds[6].innerHTML = aData[6].replace("编辑","保存");

    $(".special-num",rTds).inputmask("9{1,8}", {
        greedy : false,
        placeholder : ''
    });

}

function saveRowAddNotBillItem(oTable, nRow) {
    var rInputs = $('input', nRow);
    var aData = oTable.fnGetData(nRow);
    var dataAction = aData[6];
    var value = rInputs[0].value;
    if(nRow.children[0].children["chkPrjSku"].checked){
    	var inputChecked = "<input name='chkPrjSku' prjskuid='null' type='checkbox' checked>";
    	oTable.fnUpdate(inputChecked, nRow, 0, false);
    }
    oTable.fnUpdate(rInputs[1].value, nRow, 5, false);
    oTable.fnUpdate(dataAction.replace("保存","编辑"), nRow, 6, false);
    mapNotBill["非单据:否:"+aData[3]].factUnitPrice = rInputs[1].value;
}

/**
 * 查询非单据商品 ----------------------------------------------------------------------------
 *
 * @returns
 */
function doQuery() {
    var goodsCode = $('#skuGoodsCode').val();
    var goodsName = $('#skuGoodsName').val();
    var skuCode = $('#skuSkuCode').val();
    var skuName = $('#skuSkuName').val();
    if (goodsCode == "" && goodsName == "" && skuCode == "" && skuName == "") {
        window.top.window.showModalAlert("请选择一个检索条件");
        return;
    }

    var advData = {
        "goodsCode" : encodeURI($('#skuGoodsCode').val()),
        "goodsName" : encodeURI($('#skuGoodsName').val()),
        "skuCode" : encodeURI($('#skuSkuCode').val()),
        "skuName" : encodeURI($('#skuSkuName').val())
    };

//查询非单据商品之前需要校验 单据商品中是否存在当前查询出的非单据商品 begin-------------------------
    var billData = {};
    $.ajax({
        type: "GET",
        url: "/sysReturnManager/getOrderSkuById.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "orderId": sysReturnEdit.orderId
        },
        dataType: "json",
        ordering: false,
        async: false,
        success: function (data) {
            if (data.result == "success") {
                $.each(data.data, function (n, value) {
                    var ob = new Object();

                    ob.skuId = value.skuId;
                    ob.skuCode = value.skuCode;
                    ob.skuName = value.skuName;

                    billData[value.skuId] = ob;
                });
            } else {
                // window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
//查询非单据商品之前需要校验 单据商品中是否存在当前查询出的非单据商品 end---------------------------

//传递已经添加的非单据商品信息，用于排除再次选择情况 begin----------------------------------------------------
    $('#sysReturnSkuTable tbody tr').each(function(){
        var sysReturnSkuVO = new Object();
        var aData = $sysReturnSkuTable.fnGetData(this);
        if (!!aData) {
            if (aData[0] == "非单据") {
                // map[aData[0] + ":" + aData[1] + ":" + aData[4]].deleted = "n";
                var obj = new Object();

                var keyorderSkuId = $(this).find(".edit").attr("orderSkuId");

                obj = map[aData[0] + ":" + aData[1] + ":" + aData[4]+":"+keyorderSkuId];
                billData[map[aData[0] + ":" + aData[1] + ":" + aData[4]+":"+keyorderSkuId].skuId] = obj;
            }
        }
    });
//传递已经添加的非单据商品信息，用于排除再次选择情况 end------------------------------------------------------

    $('#addNotBillItemTable').dataTable().fnClearTable();
    $.ajax({
        type : "POST",
        url : "/stockIn/getPrjSkuList.action?formJson="+encodeURI(JSON.stringify(advData)),
//        data : JSON.stringify(advData),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        ordering: false,
        async : true,// 同步
        success : function(data) {
            if (data.result == "success") {
                $.each(data.data, function (n, value) {
                    var ob = new Object();
                    var checkbox = value.shipedQty=='0'?'':'<input name="chkPrjSku" prjSkuId="'+value.prjSkuId+'" type=\"checkbox\" />';
                    var operation = value.shipedQty=='0'?'':'<a href="javascript:;" class="edit" prjSkuId="'+value.prjSkuId+' rowIndex ="'+n+'">编辑</a>'; //&nbsp;<a href="javascript:;" class="delete" orderSkuId="'+value.orderSkuId+' rowIndex ="'+n+'">删除</a>
                    if (billData[value.skuId]){
                        addNotBillItemTable.fnAddData([
                            '',
                            value.goodsCode,
                            value.goodsName,
                            value.skuCode,
                            value.skuName,
                            '0',
                            ''
                        ]);
                    } else {
                        addNotBillItemTable.fnAddData([
                            checkbox,
                            value.goodsCode,
                            value.goodsName,
                            value.skuCode,
                            value.skuName,
                            '0',
                            operation
                        ]);
                    }

                    ob.skuId = value.skuId;
                    ob.skuCode = value.skuCode;
                    ob.skuName = value.skuName;
                    ob.goodsId = value.goodsId;
                    ob.goodsCode = value.goodsCode;
                    ob.goodsName = value.goodsName;
                    ob.qty = value.qty;
                    ob.isGifts = 'n';

                    mapNotBill["非单据:否:"+value.skuCode] = ob;
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 初始化快递单号列表数据
 */
function initLgstNoTable(){
    $('#modalAddLgstNo').modal();
    $('#addLgstNoTable').dataTable().fnClearTable();
    addLgstNoTable = $('#addLgstNoTable').dataTable({
        "bPaginate": false,
        "bAutoWidth": true,
        "bSort" : false,
        "searching": false,
        "bDeferRender": true,
        "bDestroy": true,
        "dom": '<"bottom"rtflp>'
    });
    $.ajax({
        type: "GET",
        url: "/sysRefundManager/getSysRefundListByOrderId.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "orderId": sysReturnEdit.orderId
        },
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                $.each(data.data, function (n, value) {
                    var ob = new Object();
                    var operation = '<a href="javascript:;" class="edit" lgstNo="'+value.lgstNo+' rowIndex ="'+n+'">选择</a>';
                    addLgstNoTable.fnAddData([
                        value.refundCode,
                        value.orderCode,
                        value.lgstName,
                        value.lgstNo,
                        operation
                    ]);

                });
            } else {
                // window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}




//-------------------------------------------------------------
// 从url中解析系统退货单ID
sysReturnEdit.extractId = function () {
    return extractParam("sysReturnId");
};

// 从url中解析系统订单ID
sysReturnEdit.extractOrderId = function () {
    return extractParam("sysOrderId");
};

// ===========公共方法==========

//获取页面参数
function GetArgsFromHref(sHref, sArgName) {
    var args = sHref.split("?");
    var retval = "";

    if (args[0] == sHref) /*参数为空*/
    {
        return retval;
        /*无需做任何处理*/
    }
    var str = args[1];
    args = str.split("&");
    for (var i = 0; i < args.length; i++) {
        str = args[i];
        var arg = str.split("=");
        if (arg.length <= 1) continue;
        if (arg[0] == sArgName) retval = arg[1];
    }
    return retval;
}

function extractParam(paramName) {
    var returnString = "";
    var str = window.location.search;
    if (!!str) {
        returnString = GetArgsFromHref(str, paramName);
    }
    return returnString;
}


